import { Col, Descriptions, Row, Empty, Typography, Tabs, Tag, Divider } from 'antd';
import React from 'react';
import CodeEditor from '@/components/CodeEditor';
import CustomTaskContent from './CustomTaskContent';

const { Item } = Descriptions;
const { Text } = Typography;
const { TabPane } = Tabs;

const InvocationTypeMap = {
  SpringBean: 'SpringBean',
  SpecialInterface: '自定义调用器',
};

function InvocationTaskContent({ content }) {
  const {
    invokeMethod,
    invocationType,
    arguments: args = [],
    returnValue = {},
    extension = {},
  } = content;

  const extensionSize = Object.keys(extension).length;

  return (
    <>
      <Descriptions column={4}>
        <Item label="调用类型" span={1}>
          {InvocationTypeMap[invocationType]}
        </Item>
        <Item label="调用方法名" span={3}>
          {invokeMethod}
        </Item>
      </Descriptions>
      <Row gutter={16}>
        <Col span={12}>
          <Tag color="blue">方法入参</Tag>
          <Tabs>
            {args.map(arg => (
              <TabPane tab={arg.name} key={arg.name}>
                <Text copyable={{ text: arg.type }}>参数类型：{arg.type}</Text>
                <CodeEditor
                  mode="json"
                  data={arg.value}
                  style={{ marginTop: 8 }}
                  height={550}
                  readOnly
                />
              </TabPane>
            ))}
          </Tabs>
        </Col>
        <Col span={12}>
          <Tag color="blue">方法返回值</Tag>
          <Tabs defaultActiveKey="return">
            <TabPane tab="return" key="return">
              <Text copyable={{ text: returnValue.type }}>返回值类型：{returnValue.type}</Text>
              <CodeEditor
                mode="json"
                data={returnValue.value}
                style={{ marginTop: 8 }}
                height={550}
                readOnly
              />
            </TabPane>
          </Tabs>
        </Col>
      </Row>

      {extensionSize > 0 && (
        <Row gutter={16} className="mt-2">
          <Col span={24}>
            <Tag color="blue">日志扩展信息</Tag>
            <CustomTaskContent content={extension} />
          </Col>
        </Row>
      )}
    </>
  );
}

export default InvocationTaskContent;
